# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Vesa Kaihlavirta <vegai@iki.fi>
# Contributor: David <david@pako.st>

pkgname=chicken
pkgver=5.3.0
pkgrel=5
pkgdesc='Feature rich R5RS Scheme compiler and interpreter'
arch=(loong64 x86_64)
url='https://call-cc.org/'
license=(BSD)
makedepends=(chicken)
optdepends=('tk: for the tcl/tk egg')
options=(staticlibs)
source=("https://code.call-cc.org/releases/$pkgver/$pkgname-$pkgver.tar.gz"
        CVE-2022-45145.patch)
b2sums=('7e1fb8c844542927eec53df751014f718b8c96fb6cf390d6464d7d55467c7320346be9ed05202b9c5c96548f274243ae52fead488981d7c207bec2c001db7cd7'
        '0b07d7935da0619eb2dfba4d0944c45bb5aa6d46e904125f9ee5b55ef6592d5619b7b6aa8a3136b76d8de4f3d768c6831b386a872bd6518f8b3fa04bb9f767d4')

prepare() {
  patch -Np1 -i ../CVE-2022-45145.patch -d $pkgname-$pkgver
}

build() {
  export CFLAGS+=' -ffat-lto-objects'
  export CXXFLAGS+=' -ffat-lto-objects'
  make -j1 -C $pkgname-$pkgver \
    CSC_PROGRAM=chicken-csc \
    CSI_PROGRAM=chicken-csi \
    PLATFORM=linux \
    PREFIX=/usr
}

package() {
  cd $pkgname-$pkgver
  make -j1 \
    CSC_PROGRAM=chicken-csc \
    CSI_PROGRAM=chicken-csi \
    DESTDIR="$pkgdir" \
    PLATFORM=linux \
    PREFIX=/usr \
    install
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

# getver: code.call-cc.org/releases/current/NEWS
